﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarvinsArena.Core;

namespace BattleLogic
{
	public class HudMessages: IHudMessages
	{
		private DateTime lastAdd;

		public List<GameMessage> ListMessages { get; set; }
		public string StatusMessage { get; set; }
		public bool isStatusMessageActive { get; set; }
		
		public HudMessages()
		{
			this.lastAdd = DateTime.Now;
            this.ListMessages = new List<GameMessage>();
		}

		public void AddMessage(List<string> messages)
		{
			foreach (string message in messages)
			{
				this.AddMessage(message);
			}
		}

		public void AddMessage(string message)
		{
			this.AddMessage(message, false);
		}

		public void AddMessage(string message, bool system)
		{
			this.lastAdd = DateTime.Now;
			string[] messageList = message.Split(new string[]{Environment.NewLine}, StringSplitOptions.None);

			foreach (string msg in messageList)
			{
                ListMessages.Add(new GameMessage() { System = system, TextMessage = message });
			}
		}

		public void ClearMessage()
		{
			this.ListMessages.Clear();
		}

		public void Update()
		{
			if (this.ListMessages.Count > 0 && (DateTime.Now - lastAdd).TotalSeconds > 4)
			{
				lastAdd = DateTime.Now;
				this.ListMessages.RemoveAt(0);
			}

			while (this.ListMessages.Count > 10)
				this.ListMessages.RemoveAt(0);
		}


		
	}
}
